<template>
  <el-breadcrumb class="breadcrumb" separator="/" id="guide-breadcrumb">
    <transition-group name="breadcrumb">
      <el-breadcrumb-item
        v-for="(item, index) in breadcrumbData"
        :key="item.path"
      >
        <span v-if="index === breadcrumbData.length - 1" class="no-redirect">
          {{ item.meta.title }}
        </span>
        <a v-else class="redirect" @click.prevent="handleLink(item)">{{
          item.meta.title
        }}</a>
      </el-breadcrumb-item>
    </transition-group>
  </el-breadcrumb>
</template>

<script setup lang="ts">
import { ref, watch } from "vue";
import { useRoute, useRouter, RouteLocationMatched } from "vue-router";
// import { genrateTitle } from "@/utils/i18n";
const route = useRoute();
// 路由
const breadcrumbData = ref<RouteLocationMatched[]>([]);

const getBreadcrumbData = () => {
  console.log("getBreadcrumbData:", route.matched);
  breadcrumbData.value = route.matched.filter(
    (item) => item.meta && item.meta.title
  );
};

watch(
  route,
  () => {
    getBreadcrumbData();
  },
  {
    immediate: true,
  }
);

// 点击
const router = useRouter();
const handleLink = (item: any) => {
  router.push(item.path);
};
</script>

<style lang="scss" scoped>
.breadcrumb {
  display: inline-block;
  font-size: 14px;
  line-height: 50px;
  float: left;
  :deep .no-redirect {
    color: #97a8be;
    cursor: text;
  }
}
</style>
